using System;
using System.Data;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ACME.Northwind.DataTransfer;
using ACME.Northwind.Service.Interfaces;
using ACME.Northwind.MockProxy.EventArgs;

namespace ACME.Northwind.MockProxy
{
	/// <summary>
	/// The service implementation for Product object
	/// </summary>
	public partial class ProductService : IProductService
	{
		#region IProductService Members

		/// <summary>
		/// Run the mock for the select by the primary key
		/// </summary>
		public ProductDTO SelectByPrimaryKey(int productid)
		{
			ProductPrimaryKeyEventArgs eventArgs = new ProductPrimaryKeyEventArgs(productid);
			this.OnMockProductSelectByPrimaryKey(eventArgs);
			return eventArgs.ReturnValue;
		}

		/// <summary>
		/// Run the mock for select all
		/// </summary>
		public List<ProductDTO> RunSelect()
		{
			ProductRunSelectEventArgs eventArgs = new ProductRunSelectEventArgs();
			this.OnMockProductRunSelect(eventArgs);
			return eventArgs.ReturnValue;
		}

		/// <summary>
		/// Run the mock for select with LINQ
		/// </summary>
		public List<ProductDTO> RunSelect(string linq)
		{
			ProductRunSelectLINQEventArgs eventArgs = new ProductRunSelectLINQEventArgs(linq);
			this.OnMockProductRunSelectLINQ(eventArgs);
			return eventArgs.ReturnValue;
		}

		/// <summary>
		/// Run the mock for paged select
		/// </summary>
		public PagedQueryResults<ProductDTO> RunSelect(int pageIndex, int pageSize, bool ascending, string sortColumn, string linq)
		{
			ProductRunSelectPagedEventArgs eventArgs = new ProductRunSelectPagedEventArgs(pageIndex, pageSize, ascending, sortColumn, linq);
			this.OnMockProductRunSelectPaged(eventArgs);
			return eventArgs.ReturnValue;
		}

		/// <summary>
		/// Return a list of related OrderDetail objects
		/// </summary>
		public List<OrderDetailDTO> GetOrderDetailList(ProductDTO item)
		{
			ProductDTOEventArgs eventArgs = new ProductDTOEventArgs(item);
			this.OnMockGetOrderDetailList(eventArgs);
			List<OrderDetailDTO> retval = new List<OrderDetailDTO>();
			retval.AddRange(eventArgs.ReturnDTOList.Select(x => (OrderDetailDTO)x));
			return retval;
		}

		/// <summary>
		/// Return the related Category item
		/// </summary>
		public CategoryDTO GetCategoryItem(ProductDTO item)
		{
			CategoryDTO retval = new CategoryDTO();
			ProductDTOEventArgs eventArgs = new ProductDTOEventArgs(item);
			this.OnMockGetCategoryItem(eventArgs);
			retval = (CategoryDTO)eventArgs.ReturnDTOItem;
			return retval;
		}

		/// <summary>
		/// Return the related Supplier item
		/// </summary>
		public SupplierDTO GetSupplierItem(ProductDTO item)
		{
			SupplierDTO retval = new SupplierDTO();
			ProductDTOEventArgs eventArgs = new ProductDTOEventArgs(item);
			this.OnMockGetSupplierItem(eventArgs);
			retval = (SupplierDTO)eventArgs.ReturnDTOItem;
			return retval;
		}

		/// <summary>
		/// Persists a single item
		/// </summary>
		public bool Persist(ProductDTO dto)
		{
			ProductPersistEventArgs eventArgs = new ProductPersistEventArgs(dto);
			this.OnMockProductPersist(eventArgs);
			return eventArgs.ReturnValue;
		}

		/// <summary>
		/// Persists a list
		/// </summary>
		public bool Persist(List<ProductDTO> list)
		{
			ProductPersistEventArgs eventArgs = new ProductPersistEventArgs(list);
			this.OnMockProductPersist(eventArgs);
			return eventArgs.ReturnValue;
		}

		/// <summary>
		/// Delete a single item
		/// </summary>
		public bool Delete(ProductDTO dto)
		{
			ProductDeleteEventArgs eventArgs = new ProductDeleteEventArgs(dto);
			this.OnMockProductDelete(eventArgs);
			return eventArgs.ReturnValue;
		}

		#endregion

		#region Product Events

		partial void GetSelectByPrimaryKey();

		/// <summary>
		/// The event for the SelectByPrimaryKey method
		/// </summary>
		public event EventHandler<ProductPrimaryKeyEventArgs> MockProductSelectByPrimaryKey;

		/// <summary>
		/// Raises the OnMockRegistrationCodeSelectByPrimaryKey event
		/// </summary>
		protected virtual void OnMockProductSelectByPrimaryKey(ProductPrimaryKeyEventArgs e)
		{
			if (this.MockProductSelectByPrimaryKey != null)
				this.MockProductSelectByPrimaryKey(this, e);
		}

		/// <summary>
		/// The event for the RunSelect method
		/// </summary>
		public event EventHandler<ProductRunSelectEventArgs> MockProductRunSelect;

		/// <summary>
		/// Raises the OnMockRunSelect event
		/// </summary>
		protected virtual void OnMockProductRunSelect(ProductRunSelectEventArgs e)
		{
			if (this.MockProductRunSelect != null)
				this.MockProductRunSelect(this, e);
		}

		/// <summary>
		/// The event for the RunSelectLINQ method
		/// </summary>
		public event EventHandler<ProductRunSelectLINQEventArgs> MockProductRunSelectLINQ;

		/// <summary>
		/// The event for the OnMockRunSelectLINQ method
		/// </summary>
		protected virtual void OnMockProductRunSelectLINQ(ProductRunSelectLINQEventArgs e)
		{
			if (this.MockProductRunSelectLINQ != null)
				this.MockProductRunSelectLINQ(this, e);
		}

		/// <summary>
		/// The event for the RunSelectPaged method
		/// </summary>
		public event EventHandler<ProductRunSelectPagedEventArgs> MockProductRunSelectPaged;

		/// <summary>
		/// The event for the OnMockRunSelectPaged method
		/// </summary>
		protected virtual void OnMockProductRunSelectPaged(ProductRunSelectPagedEventArgs e)
		{
			if (this.MockProductRunSelectPaged != null)
				this.MockProductRunSelectPaged(this, e);
		}

		/// <summary>
		/// The event for the GetOrderDetailList method
		/// </summary>
		public event EventHandler<ProductDTOEventArgs> MockGetOrderDetailList;

		/// <summary>
		/// The event for the OnMockGetOrderDetailList method
		/// </summary>
		protected virtual void OnMockGetOrderDetailList(ProductDTOEventArgs e)
		{
			if (this.MockGetOrderDetailList != null)
				this.MockGetOrderDetailList(this, e);
		}

		/// <summary>
		/// The event for the GetCategoryItem method
		/// </summary>
		public event EventHandler<ProductDTOEventArgs> MockGetCategoryItem;

		/// <summary>
		/// The event for the OnMockGetCategoryItem method
		/// </summary>
		protected virtual void OnMockGetCategoryItem(ProductDTOEventArgs e)
		{
			if (this.MockGetCategoryItem != null)
				this.MockGetCategoryItem(this, e);
		}

		/// <summary>
		/// The event for the GetSupplierItem method
		/// </summary>
		public event EventHandler<ProductDTOEventArgs> MockGetSupplierItem;

		/// <summary>
		/// The event for the OnMockGetSupplierItem method
		/// </summary>
		protected virtual void OnMockGetSupplierItem(ProductDTOEventArgs e)
		{
			if (this.MockGetSupplierItem != null)
				this.MockGetSupplierItem(this, e);
		}

		/// <summary>
		/// The event for the Persist method
		/// </summary>
		public event EventHandler<ProductPersistEventArgs> MockProductPersist;

		/// <summary>
		/// Raises the OnMockPersist event
		/// </summary>
		protected virtual void OnMockProductPersist(ProductPersistEventArgs e)
		{
			if (this.MockProductPersist != null)
				this.MockProductPersist(this, e);
		}

		/// <summary>
		/// The event for the Delete method
		/// </summary>
		public event EventHandler<ProductDeleteEventArgs> MockProductDelete;

		/// <summary>
		/// Raises the OnMockDelete event
		/// </summary>
		protected virtual void OnMockProductDelete(ProductDeleteEventArgs e)
		{
			if (this.MockProductDelete != null)
				this.MockProductDelete(this, e);
		}

		#endregion

	}
}
